//
//  MCNNavHistoryStackCell.swift
//  MCNNavHistoryStackCell
//
//  Created by yhbj on 2021/9/16.
//

import UIKit

class MCNNavHistoryStackCell: UICollectionViewCell {
    var historyStackModel: MCNNavHistoryStackModel? {
        didSet {
            contentLabel?.text = historyStackModel!.title
            if historyStackViewStyle == .Light {
                contentView.backgroundColor = MCNNavHistoryStackViewStyleLightBackgroundColor
                contentLabel?.textColor = .black
            } else {
                contentView.backgroundColor = MCNNavHistoryStackViewStyleDarkBackgroundColor
                contentLabel?.textColor = .white
            }
            if historyStackModel!.isSelected {
                if historyStackViewStyle == .Light {
                    contentView.backgroundColor = MCNNavHistoryStackViewStyleLightSelectedColor
                } else {
                    contentView.backgroundColor = MCNNavHistoryStackViewStyleDarkSelectedColor
                }
            }
        }
    }
    var historyStackViewStyle: MCNNavHistoryStackViewStyle?
    
    private var contentLabel: UILabel?
    private var lineView: UIView?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUp()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUp() {
        contentLabel = UILabel()
        contentLabel?.font = UIFont.systemFont(ofSize: 17)
        lineView = UIView()
        lineView?.backgroundColor = .red
        addSubview(contentLabel!)
        addSubview(lineView!)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        contentLabel?.frame = CGRect(x: MCNNavHistoryStackCellTitleX, y: 0, width: mcn_width - MCNNavHistoryStackCellTitleX * 2, height: self.mcn_height)
        lineView?.frame = CGRect(x: 0, y: mcn_height - 0.5, width: mcn_width, height: 0.5)
        lineView?.backgroundColor = MCNNavDefaultLineColor
    }
}
